/*
 * This class implements one simulation as a callable, it is used with multi threading 
 */

package javaapplication6.MODEL.MULTI;

import java.util.Random;
import java.util.concurrent.Callable;

/**
 * Implementation of a single simulation
 * @author M
 */
public final class OneSimulation implements Callable<Double>{
    private final Random random ;
    private double st;
    private final double nSteps;
    private final double drift;
    private final double vSqrt;
    private final double s;

    /**
     * Constructor to initialize the MonteCarlo simulation parameters
     * @param st
     * @param nSteps
     * @param drift
     * @param vSqrt
     * @param s 
     */
    public OneSimulation(double st, double nSteps, double drift, double vSqrt, double s) {
        this.random = new Random();
        this.st = st;
        this.nSteps = nSteps;
        this.drift = drift;
        this.vSqrt = vSqrt;
        this.s = s;
    }
    
    /**
     * Method to calculate a Monte Carlo simulation
     * @return the price of an option
     * @throws Exception 
     */
    @Override
    public Double call() throws Exception {
        st = s;
        for(int j = 1; j <= nSteps ; j++){
            st *= Math.exp(drift + (vSqrt * random.nextGaussian()));
        }
        //System.out.println(Thread.currentThread().getId());
        return st;    
    }
}
